import VueRouter from 'vue-router';
import store from '@/store';
export default ( /**@type {VueRouter} */ router) => {
  router.beforeEach(async (to, from, next) => {
    const getToken = await store.dispatch('user/sendMe')
    if (getToken) {
      if (to.path === '/login') {
        next('/')
      } else {
        if (!store.getters.portrait) {
          try {
            await store.dispatch('user/sendMe')
            next()
          } catch (error) {
            next('/login')
          }
        } else {
          next()
        }
      }
    } else {
      if (to.meta.loged) {
        next('/login')
      } else {
        next()
      }
    }
  })
}